﻿
Imports System.IO
Imports PilotKaraoke.ApplicationFramework.ApplicationTips

Public NotInheritable Class Utilities

#Region " Private Constructor "

    ''' <summary>
    ''' This constructor is intentionally private to prevent instantiation as this class only contains static members.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub New()
        'Do nothing.
    End Sub

#End Region

#Region " Static Methods "

    ''' <summary>
    ''' Gets the active path where application data files can be stored.
    ''' </summary>
    ''' <returns>String - the path where the data file is located including the data file name.</returns>
    ''' <remarks>If the data file is not located in the user data folder then the data file will be copied from the
    ''' default location to the application's user data folder.  This is helpful to avoid any potential security issues
    ''' that might arrise from writing to the default data file path.</remarks>
    Friend Shared Function GetResolvedDataFilePath(ByVal dataFilename As String) As String
        Dim userDataFilePath As String = Path.Combine( _
                                                       My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData, _
                                                       dataFilename)

        'The default path is where the data file is initially deployed during application setup.  This is in the deployment path
        'of the application itself which should not typically be written to (especially with Win Vista and Win 7).
        Dim defaultDataFilePath As String = Path.Combine( _
                                                          My.Application.Info.DirectoryPath & _
                                                          Path.DirectorySeparatorChar & _
                                                          My.Settings.DataFileFolderName, _
                                                          dataFilename)

        If My.Computer.FileSystem.FileExists(userDataFilePath) Then
            Return userDataFilePath
        Else
            'Copy the file to the user data location from the default location and return the path to the user data location.
            My.Computer.FileSystem.CopyFile(defaultDataFilePath, userDataFilePath, overwrite:=False)
            Return userDataFilePath
        End If

    End Function

    ''' <summary>
    ''' Gets the font syle of the given font object
    ''' </summary>
    ''' <param name="theFont">Font - the font for which to return the font style.</param>
    ''' <returns>FontFtyle</returns>
    ''' <remarks></remarks>
    Friend Shared Function GetFontStyle(ByVal theFont As Font) As FontStyle
        Dim style As FontStyle = FontStyle.Regular
        If theFont.Bold Then
            style = style Or FontStyle.Bold
        End If
        If theFont.Italic Then
            style = style Or FontStyle.Italic
        End If
        If theFont.Underline Then
            style = style Or FontStyle.Underline
        End If
        If theFont.Strikeout Then
            style = style Or FontStyle.Strikeout
        End If
        Return style
    End Function

    ''' <summary>
    ''' Shows the next Application Tip
    ''' </summary>
    ''' <param name="forceTipDisplay">Boolean - when True, forces the tip to show, even if the settings are set otherwise.</param>
    ''' <remarks></remarks>
    Friend Shared Sub ShowTipsAtStartup(Optional ByVal forceTipDisplay As Boolean = False)

        'The following code demonstrates the use of the Application Tips library to show tips at startup.
        If My.Settings.ShowTipsAtStartup OrElse forceTipDisplay Then
            Using manager As New TipManager(Utilities.GetResolvedDataFilePath(My.Settings.TipsFileName), TipDisplayMethod.Normal)
                manager.ShowTipsAtStartup = My.Settings.ShowTipsAtStartup
                manager.ShowApplicationTip()
                My.Settings.ShowTipsAtStartup = manager.ShowTipsAtStartup
            End Using
        End If

    End Sub

#End Region

End Class
